using NUnit.Framework;
using Typed.Configuration.ConfigSource;

namespace Typed.Configuration.Tests
{
    [TestFixture]
    public class ConfigServiceUsage
    {
        // Define interface with configuration properties
        public interface IConfigInterface
        {
            [FieldName("FooCount")]
            int? ItemsPerPage { get; }
            
            [FieldName("NotExistingField")]
            int? NotExistingField { get; }
        }

        [Test]
        public void FullUsageScenarioForStubSource()
        {
            var configurationServiceBuilder = new ConfigurationServiceBuilder();

            // Register configuration interface within service
            configurationServiceBuilder.RegisterConfigInterface<IConfigInterface>(new AppSettingsSource(), new NullValueSource());

            // Create service instance and put it to your IoC container, or store in static vairable
            ConfigurationService configService = configurationServiceBuilder.Build();

            // Get configuration property value
            int? itemsPerPageCount = configService.For<IConfigInterface>().ItemsPerPage;
            Assert.AreEqual(98, itemsPerPageCount);
            int? notExistingValue = configService.For<IConfigInterface>().NotExistingField;
            Assert.IsNull(notExistingValue);
        }
    }
}